package com.thoughtorigin.flux.asflux {
import com.thoughtorigin.flux.Flux;

public class ReferenceProperty implements Property {

    private var _propertyName: String;
    private var _ioc: Flux;
    private var _refPropertyName: String;
    private var _createNew: Boolean;

    public function ReferenceProperty(propertyName: String, ioc: Flux, refPropertyName: String, createNew: Boolean = false) {
        _propertyName = propertyName;
        _ioc = ioc;
        _refPropertyName = refPropertyName;
        _createNew = createNew;
    }

    public function get propertyName():String {
        return _propertyName;
    }

    public function get value():Object {
        if(_createNew) {
            return _ioc.createNew(_refPropertyName);
        }
        return _ioc.getProperty(_refPropertyName);
    }
}
}